package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        Teacher teacher = new Teacher();
        teacher.name = "范传奇";
        System.out.println(teacher.name);


        Class cls = Class.forName("reflect.Teacher");
        Object obj = cls.newInstance();
        Field field = cls.getField("name");
        field.set(obj,"王克晶");
        System.out.println(field.get(obj));


        Field field2 = cls.getDeclaredField("age");
        field2.setAccessible(true);
        field2.set(obj,22);
        System.out.println(field2.get(obj));
        field2.setAccessible(false);
    }
}
